/**
 * describe:
 *
 * @author chaP
 * @date 2018/12/27
 */
package CodingTest;

public class isSymmetric {
    private class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x){val = x;}
    }
    public boolean isSymmetric(TreeNode root){
        if(root == null || (root.left == null && root.right == null)){
            return true;
        }
        return judge(root.left,root.right);
    }


    public boolean judge(TreeNode p,TreeNode q){
        if(p == null && q == null){
            return true;
        }
        if(p ==null || q == null){
            return false;
        }
        return (p.val == q.val)&&judge(p.left,q.right)&&judge(p.right,q.left);
    }
}
